package com.wzdigit.wms.wms.rpc.wms2oms;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.wms.basic.domain.transfer.GdnHeader;
import com.wzdigit.wms.wms.api.wms2oms.GdnApi;
import com.wzdigit.wms.wms.dto.wms2oms.GdnCntrInfoDto;
import com.wzdigit.wms.wms.service.core.GdnManagerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@Slf4j
@Service(version = "${dubbo.providers.wms.gdnCntr.api:1.0.0}")
public class GdnApiImplService implements GdnApi {

    @Autowired
    private GdnManagerService gdnManagerService;

    /**
     * 通过 发货单号/源单号 获取单据对应的柜号编码
     *
     * @param billNo
     * @return
     */
    @Override
    public GdnCntrInfoDto getCntrInfoByNo(String billNo) throws Exception {
        QueryWrapper<GdnHeader> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("GDN_NO", billNo).or().eq("SOURCE_SHIP_NOTICE", billNo);
        queryWrapper.select("GDN_NO", "SOURCE_SHIP_NOTICE", "CNTR_NO");
        List<GdnHeader> gdnHeaders = this.gdnManagerService.getGdnHeaderMapper().selectList(queryWrapper);
        if (gdnHeaders.size() == 0) {
            throw new Exception("没有找到单据信息!");
        }
        GdnHeader gdnHeader = gdnHeaders.get(0);
        GdnCntrInfoDto dto = new GdnCntrInfoDto();
        dto.setGdnNo(gdnHeader.getGdnNo());
        dto.setSourceNo(gdnHeader.getSourceShipNotice());
        dto.setCntrNo(gdnHeader.getCntrNo());
        return dto;
    }
}
